#ifndef __SYSTEM_SERVER_H__
#define __SYSTEM_SERVER_H__

#include <map>
#include <mutex>
#include <functional>
#include "Util/util.h"
#include "jsoncpp/json.h"
#include "Network/Buffer.h"

using namespace std;
class SystemServer //: public Fdt::make_shared_base<Config>
{
public:
	using ConfigFunc = std::function<bool(Json::Value &, int &result)>;
	static SystemServer *instance()
	{
		if(s_systemServer == nullptr)
		{
			s_systemServer = new SystemServer();
		}
		return s_systemServer;
	}

	~SystemServer(){}

	void RegistRPC();

	bool GetTime(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);
	
	bool SetTimeMs(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);

	bool SetTime(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);

	bool GetPower(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);

	bool SetLive(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);

	bool CheckPasswd(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);

	bool GetUvcStatus(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);
	
	bool GetDevInfo(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);

	bool GetAudioIn(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);

	bool GetDeviceList(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);
	bool Subscribe(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);
protected:
	SystemServer();
private:
	static SystemServer *			s_systemServer;
	std::recursive_mutex			_mutex;

	std::map<std::string, std::map<void *, ConfigFunc>> _setMap;
	std::map<std::string, std::map<void *, ConfigFunc>> _verifyMap;

};
#endif
